package com.lazar.model;

import com.lazar.dao.AdminDao;

import java.io.Serializable;

public class Admin  implements Serializable {

    private static final long serialVersionID = 1L;

    private int uid;
    private String name;
    private String pass;

    public static long getSerialVersionID() {
        return serialVersionID;
    }

    public int getUid() {
        return uid;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getPass() {
        return pass;
    }

    public void setPass(String pass) {
        this.pass = pass;
    }

    @Override
    public String toString() {
        return "Admin{" +
                "uid=" + uid +
                ", name='" + name + '\'' +
                ", pass='" + pass + '\'' +
                '}';
    }

    public boolean login() throws Exception {
        AdminDao dao = new AdminDao();
        Admin admin1 = dao.getAdmin(this.name);

        if (admin1 == null){
            throw new Exception("用户名密码错误");
        }
        if (!this.pass.equals(admin1.pass)){
            throw new Exception("用户名密码错误");
        }

        return true;
    }
}
